# Contributor: Michael Zuo <muh.muhten@gmail.com>
# Contributor: Sora Morimoto <sora@morimoto.io>
# Contributor: Anil Madhavapeddy <anil@recoil.org>
# Contributor: omni <omni+alpine@hack.org>
# Maintainer: Kate <kit.ty.kate@disroot.org>
pkgname=opam
pkgver=2.2.1
pkgrel=0
pkgdesc="OCaml Package Manager"
url="https://opam.ocaml.org"
arch="all"
license="LGPL-2.1-only WITH OCaml-LGPL-linking-exception"
depends="curl patch unzip coreutils bubblewrap"
options="!check" # The tests use bubblewrap which cannot be run inside docker
makedepends="dune tar ocaml-compiler-libs"
checkdepends="rsync bash diffutils"
source="https://github.com/ocaml/opam/releases/download/$pkgver/opam-full-$pkgver.tar.gz"
subpackages="$pkgname-doc"
builddir="$srcdir/opam-full-$pkgver"

case "$CARCH" in
	riscv64|loongarch64)
		makedepends="${makedepends//ocaml/ocaml5}"
		;;
esac

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--with-mccs \
		--with-vendored-deps \
		--with-dune=/usr/bin/dune

	make -j1 all
}

check() {
	make tests
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
}

sha512sums="
4d7cd4755ba658e0ef4a119dd9d014a610fb909a73a111f922467a309c9599f86aec6b07295fc8335910b00b94ba22d329d9363fae987ab0cc4ec89e58bbaa43  opam-full-2.2.1.tar.gz
"
